from fastapi import APIRouter, Query, Depends
from src.modules.knowbase.services.Impl.kb_service import KBService
from core.schemas.response import success,fail,StandardResponse
from src.modules.knowbase.services.Interface.kb_interface import IKbInterface

router = APIRouter(prefix="/kb", tags=["kb"])
from src.modules.knowbase.services.containers import Container
container = Container()
kb_service = container.kb_service()

@router.get("/list")
async def get_kb_list(user_id: str = Query(None, description="用户id，分权分域用"),
                      keyword: str = Query(None, description="关键词，用于查询知识库列表"),
                      page: int = Query(1, description="页码", ge=1),
                      page_size: int = Query(10, description="每页条数", le=100)):
    return await kb_service.get_kb_list(user_id, keyword, page, page_size)

@router.post("/create",response_model=StandardResponse)
async def create_kb(kb_name:str):
    result = await kb_service.create_kb(kb_name)
    print(result)
    if result is None:
        return fail(data=f"知识库{kb_name}创建失败")
    return success(data=f"知识库{kb_name}创建成功")

@router.delete("/delete/{kb_id}")
async def delete_by_file_id(kb_id:str):
    flag = await kb_service.delete_by_kb_id(kb_id)
    if not flag:
        return fail(data = flag)
    return success(data = flag)
